<?php
	define(BASE_URL, "http://jansensan.net/projects/communication-between-as3-and-facebook/");
	
	$img_id = "click_to_activate_id";
	$img_src = BASE_URL . "images/click_to_activate.jpg";
	$swf_id = "communication_with_fb_id";
	$swf_src = BASE_URL . "communication_with_fb.swf";
?>


<style type="text/css">
	<!--
	h1
	{
		border-top:2px solid #6d6d6d;
		padding:8px 0;
	}
	
	#wrapper
	{
		width:520px;
		background-color:#ffffff;
	}
	
	#swfWrapper
	{
		width:520px;
		height:600px;
		margin-bottom:16px;
	}
	
	#buttonsWrapper
	{
		width:520px;
		margin:0 auto;
	}
	
	.button
	{
		cursor:pointer;
		background-image:url(<?php echo BASE_URL ?>images/button.jpg);
		width:96px;
		height:16px;
		margin:0 auto;
		padding:4px 0;
		font-family:Helvetica, Arial, sans-serif;
		font-size:16px;
		text-align:center;
		color:#000;
	}
	
	.hasPointer
	{
		cursor:pointer;
	}
	-->
</style>


<script type="text/javascript">
	function embedSWF()
	{
		// remove image
		var image = document.getElementById("<?php echo $img_id ?>");
		document.getElementById("swfWrapper").removeChild(image);
		
		// create swf object
		var swf = document.createElement("fb:swf");
		swf.setId("<?php echo $swf_id ?>");
		swf.setWidth("520");
		swf.setHeight("600");
		swf.setSWFSrc("<?php echo $swf_src ?>");
		document.getElementById("swfWrapper").appendChild(swf);
	}
	
	
	function fbjsFunctionForAS3(title, message)
	{
		new Dialog().showMessage(title, message);
	}
	
	
	function buttonClickHandler()
	{
		var swf = document.getElementById("<?php echo $swf_id ?>");
		if(swf)
		{
			swf.callSWF("as3FunctionForFBJS", "Message sent from FBJS", "Facebook says hello!");
		}
		else
		{
			new Dialog().showMessage("Flash not yet embedded", "The Flash file has not yet been embedded into the page. Click the image to activate the Flash file first, then you will be able to use this button.");
		}
	}
</script>


<div id="wrapper">
	
	<h1>Flash Area</h1>
	
	<div id="swfWrapper">
	
		<fb:fbjs-bridge/>
	
		<img
			src="<?php echo $img_src ?>" 
			id="<?php echo $img_id ?>" 
			width="520" height="600" 
			class="hasPointer"
			onclick="embedSWF()" 
		/>
		
	</div>
	
	
	<h1>HTML Area</h1>
	
	<div id="buttonsWrapper">
		<div
			id="button01"
			class="button"
			onclick="buttonClickHandler()"
			>
			Call AS3
		</div>
	</div>
	
</div>